monthly_deposits = benchmark_results["NetDeposit"].resample("ME").sum()
fig = make_subplots(specs=[[{"secondary_y": True}]])
# Personal Portfolio Value
fig.add_trace(
go.Scatter(
x=portfolio_value.index,
y=portfolio_value,
mode="lines",
name="Personal Portfolio",
line=dict(color="green", width=2),
),
secondary_y=False,
)
# Benchmark Value
fig.add_trace(
go.Scatter(
x=benchmark_results.index,
y=benchmark_results["TotalValue"],
mode="lines",
name=f"{config.BENCHMARK_INDEX} Benchmark",
line=dict(color="red", width=2),
),
secondary_y=False,
)
# Cumulative Net Deposits
fig.add_trace(
go.Scatter(
x=benchmark_results.index,
y=benchmark_results["NetDeposit"].cumsum(),
mode="lines",
name="Cumulative Net Deposits",
line=dict(color="darkgrey", width=1, dash="dash"),
),
secondary_y=False,
)
# Monthly Deposits/Withdrawals (on secondary y-axis)
fig.add_trace(
go.Bar(
x=monthly_deposits.index,
y=monthly_deposits,
name="Deposits / Withdrawals",
marker_color="royalblue",
opacity=0.4,
),
secondary_y=True,
)
fig.update_layout(
title_text=f"Portfolio Performance vs. {config.BENCHMARK_INDEX} Benchmark",
template="plotly_white",
barmode="relative",
legend=dict(orientation="h"),
xaxis=dict(
title="Date",
type="date"
),
)
fig.update_yaxes(
title_text=f"<b>Portfolio Value ({config.BASE_CURRENCY})</b>", secondary_y=False
)
fig.update_yaxes(
title_text="<b>Monthly Cash Flow</b>",
secondary_y=True,
showgrid=False,
layer="below traces",
)
fig.show()